const express = require('express')
const router = express.Router()
module.exports = app => {

    router.get('/', async(req, res) => {
        let { User } = require('../data/User')
        res.send(User)
    })

    router.post('/login', async(req, res) => {
        let { username, password, } = req.body
        res.send({ "messgae": username === 'admin' })
    })

    // 书城分类模块
    // 一级分类
    router.get('/classify/firstClassify', async(req, res) => {

        let data = {
            "male": [{
                "id": 1,
                "channelId": 4,
                "sortName": "玄幻",
                "parentId": 0,
                "bookCount": 41,
                "booksList": null,
                "createTime": "2020-06-01T08:29:15.000+0000"
            }],
            "female": [{
                "id": 15,
                "channelId": 7,
                "sortName": "古代言情",
                "parentId": 0,
                "bookCount": 10,
                "booksList": null,
                "createTime": "2020-06-01T08:29:15.000+0000"
            }]
        }
        res.send(data)
    })

    // 二级分类莫夸
    router.get('/classify/secondClassify', async(req, res) => {

        let data = [{
            "id": 24,
            "channelId": 4,
            "sortName": "东方玄幻",
            "parentId": 1,
            "bookCount": null,
            "booksList": [{
                "id": 15,
                "booksName": "衍仙纪",
                "author": "衍仙纪",
                "sortId": "24",
                "booksCover": "url",
                "booksDescription": ""
            }]
        }]
        res.send(data)
    })

    // 搜索部分
    router.get('/search/:parmes', async(req, res) => {
        let data = {
            "total": 46,
            "totalPage": 1,
            "rows": [{
                "id": 22,
                "booksName": "<span style='color:red'>东</span><span style='color:red'>皇</span><span style='color:red'>大帝</span>",
                "author": "东皇大帝",
                "sortId": "24",
                "booksCover": "http://bookcover.yuewen.com/qdbimg/349573/1019254153/180",
                "booksDescription": "xxxx",
                "readerSex": "女",
                "createTime": "2020-06-02T20:57:50.000+0000",
                "over": false
            }]
        }
        res.send(data)
    })


    // 核心阅读器部分
    // 查询本章节的目录
    router.get('/chapter/findAll/:id', async(req, res) => {
        let data = {
            "flag": true,
            "code": 20000,
            "message": "查询成功",
            "data": [{
                "id": 1601,
                "bookId": "15",
                "chapterName": "第1章 出手",
                "costChunJuan": 5.0,
                "lastChapterId": null,
                "nextChapterId": null,
                "createTime": "2020-06-02T14:58:55.000+0000",
                "directoryList": [{
                    "id": 1,
                    "bookId": "15",
                    "secondChapter": "chapter-1601-1",
                    "chapterId": 1601
                }]
            }]
        }

        res.send(data)
    })

    // 根据id查询本章节的价格
    router.get('/chapter/findById/1601', async(req, res) => {
        let data = {
            flag: true,
            code: 20000,
            message: "查询成功",
            data: {
                id: 1601,
                bookId: 15,
                chapterName: "第1章 出手",
                costChunJuan: 5,
                lastChapterId: null,
                nextChapterId: null,
                createTime: "2020-06-02T14:58:55.000+0000",
                directoryList: null
            }
        }
        res.send(data)
    })

    // 根据id查询本章节的价格
    router.get('/user/findById/1', async(req, res) => {
        let data = {
            flag: true,
            code: 200,
            message: "查询成功",
            data: {
                id: 1,
                nickName: "爱阅读",
                sex: "男",
                avaTor: "老舍",
                tel: "13388889999",
                email: "123456789@qq.com",
                loginPwd: "123456",
                createTime: null,
                lastLoginTime: "2020-06-04 16:43:12",
                gold: 100,
                integral: 10
            }
        }
        res.send(data)
    })

    // 根据id查询本章节的价格
    router.get('/books/4', async(req, res) => {
        let data = {
            "flag": true,
            "code": 20000,
            "message": "查询成功",
            "data": {
                "id": 4,
                "books_name": "神道大至尊",
                "author": "神道大至尊",
                "sort_id": "30",
                "is_over": false,
                "books_cover": "http://bookcover.yuewen.com/qdbimg/349573/1019254153/180",
                "books_description": "xxxx",
                "reader_sex": "男",
                "create_time": "2020-06-02T11:05:50.000+0000",
                "count": 1
            }
        }
        res.send(data)
    })



    app.use('/api', router)
}